<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>

<form:form commandName="taskMain" cssClass="form-horizontal" role="form" onsubmit="return false;"
           enctype="multipart/form-data">
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="taskName">
            <a style="color: red">*</a>任务名称
        </label>
        <div class="col-sm-8">
            <input type="text" name="mainName" id="taskName" placeholder="任务名称" value="${taskMain.mainName}"
                   class="form-control required">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="content">任务内容</label>
        <div class="col-sm-8">
            <textarea rows="5" id="content" name="content" placeholder="任务内容"
                      class="form-control">${taskMain.content}</textarea>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right">任务附件</label>
        <div class="col-sm-6">
            <input type="file" id="fileupload" name="files" class="form-control">
        </div>
        <div class="col-sm-2">
            <input type="button" value="上传" id="btn-upload" style="width: 100%; height: 32px;"
                   class="btn-large btn-primary"/>
            <input type="text" name="file" id="file" value="${taskMain.file}" class="form-control "
                   style="display: none"/>
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label no-padding-right" for="dateTime"><a style="color: red">*</a>任务时限</label>
        <c:if test="${taskMain.categoryId=='20190807100000000001'}">
            <div class="col-sm-3">
                <input type="text" name="timeLimit" id="dateTime" placeholder="任务时限" value="${taskMain.timeLimit}"
                       class="form-control  required"/>
            </div>
        </c:if>
        <c:if test="${taskMain.categoryId!='20190807100000000001'}">
            <div class="col-sm-3">
                <input type="text" name="timeLimit" id="date-picker" placeholder="任务时限" value="${taskMain.timeLimit}"
                       class="form-control  required date-picker"/>
            </div>
        </c:if>
        <label class="col-sm-2 control-label no-padding-right " for="referenceNumber"><span
                style="color: red;">*</span>文号</label>
        <div class="col-sm-3">
            <input type="text" name="fileNumber" id="referenceNumber" placeholder="文号"
                   value="${taskMain.fileNumber}"
                   class="form-control required">
        </div>
        <div class="col-sm-1">
            <button onclick="NewlyAdded()" class="btn btn-sm btn-success">新增议题</button>
        </div>
    </div>
    <c:forEach items="${subFilterList}" var="subFilter" varStatus="index">
        <div class="form-group">
            <label class="col-sm-2 control-label no-padding-right" for="dateTime"><a
                    style="color: red">*</a>子任务</label>
            <div class="col-sm-8">
                <textarea rows="1" name="taskSubFilterList[${index .index}].subName" placeholder="请输入子任务"
                      class="form-control">${subFilter.subName}</textarea>
                <input name="taskSubFilterList[${index .index}].sysId" value="${subFilter.sysId}" type="hidden">
            </div>
            <div class="col-sm-1">
                <button class="btn btn-sm btn-danger"  onclick="delTasks('${subFilter.sysId}')">删除任务</button>
            </div>
        </div>
    </c:forEach>


    <input id="sysId" name="sysId" value="${taskMain.sysId}" type="hidden">
    <input id="categoryId" name="categoryId" value="${taskMain.categoryId}" type="hidden">

</form:form>
<script src="<s:url value="/assets/js/chosen.jquery.js"></s:url>"></script>
<script src="<s:url value="/assets/js/ajaxfileupload.js"></s:url>"></script>
<script src="<s:url value="/assets/js/modal/modal.js"></s:url>"></script>

<script type="text/javascript">
    jQuery(function ($) {
        $('.date-picker').datepicker({
            inline: true,
            format: "yyyy-mm-dd",
            autoclose: true,
            todayHighlight: true,
            language: 'cn'
        })
        //show datepicker when clicking on the icon
            .next().on(ace.click_event, function () {
            $(this).prev().focus();
        });
    });

    /**
     * 删除子任务
     */
    function delTasks(sysId) {
        var $sysId = $("#sysId").val();
        var Determine =  confirm("是否删除");
        if (Determine) {
            $.post(getUrl("deleteSub")+sysId,function (data) {
                data == "200" ? alert("删除成功") : alert("删除失败");
            })
            loadDialog({
                dialogTitle: '修改任务',
                dialogUrl: "/taskMain/update/" + $sysId,
                dialogFoot: '<button type="button" class="btn btn-primary" onclick="updateModify()">修改</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>',
            });
        }
    }

    /**
     * NewlyAdded 新增议题
     */
    function NewlyAdded() {
        var $sysId = $("#sysId").val();
        loadDialog({
            dialogTitle: '新增议题',
            dialogUrl: getUrl("addTaskSub")+ $sysId,
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="addYt()">确认</button>' +
            '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    };
</script>
